﻿<c:BaseControl x:Class="personalplaner.gui.stamm.views.PlanLayoutStamm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
             xmlns:fac="clr-namespace:personalplaner.gui.stamm.viewmodels.factories"
             vm:ViewModelLoader.FactoryType="{x:Type fac:PlanSchemaStammModelFactory}"
             xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
               xmlns:p="clr-namespace:personalplaner.gui.Properties" 
               Name="baseControl"
             Background="Transparent"
             Foreground="#E1000000">


    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>
                <ResourceDictionary>
                    <BooleanToVisibilityConverter x:Key="boolToVis"/>
                    <conv:BoolToInvertVisibilityConverter x:Key="boolInverVis"/>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>
    
    <Grid>

        <Grid.Resources>

            <conv:ColorToSolidColorBrushConverter x:Key="colorToBrush"/>
            
            <DataTemplate DataType="{x:Type bs:PlanSchema}">
                <Grid Margin="0,0,20,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Name="txtId" Text="{Binding ID}" Grid.Column="0" Margin="5,0,5,0"/>
                    <TextBlock Name="txtName" Text="{Binding Name}" Grid.Column="1"/>
                </Grid>
                
                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Status}" Value="Inactive">
                        <Setter TargetName="txtId" Property="Foreground" Value="Red"/>
                        <Setter TargetName="txtName" Property="Foreground" Value="Red"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
                
            </DataTemplate>

            <DataTemplate DataType="{x:Type bs:PlanSchemaItem}">
                <Border HorizontalAlignment="Stretch">
                    <Grid Margin="0,0,0,0" Background="{Binding Color, Converter={StaticResource colorToBrush}}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding PersonSchemaID}" Grid.Column="0" Margin="5,0,0,0" x:Name="schemaID"/>
                        <TextBlock Text="{Binding PrsID}" Grid.Column="1" Visibility="Collapsed" Margin="5,0,0,0" x:Name="prsId" />

                        <!--<TextBlock Text="{Binding Vorname}" Grid.Column="2" Margin="5,0,0,0" x:Name="vorname"/>
                    <TextBlock Text="{Binding Nachname}" Grid.Column="3" Margin="5,0,0,0" x:Name="nachname"/>-->
                        <TextBlock Text="{Binding DisplayName}" Grid.Column="2" Margin="5,0,0,0" x:Name="name"/>

                        <TextBlock Text="{Binding AbteilungName}" Grid.Column="4" x:Name="abteilung" Visibility="Collapsed"/>
                    </Grid>
                </Border>

                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding ShowPrsId}" Value="True">
                        <Setter TargetName="prsId" Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                    
                    <DataTrigger Binding="{Binding PrsID}" Value="0">
                        <Setter TargetName="schemaID" Property="Visibility" Value="Collapsed"/>
                        <!--<Setter TargetName="vorname" Property="Visibility" Value="Collapsed"/>-->
                        <!--<Setter TargetName="nachname" Property="Visibility" Value="Collapsed"/>-->
                        <Setter TargetName="name" Property="Visibility" Value="Collapsed"/>
                        <Setter TargetName="prsId" Property="Visibility" Value="Collapsed"/>

                        <Setter TargetName="abteilung" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="abteilung" Property="FontWeight" Value="Heavy"/>
                        <Setter TargetName="abteilung" Property="FontSize" Value="14"/>
                        <Setter TargetName="abteilung" Property="Foreground" Value="#80000000"/>
                        <Setter TargetName="abteilung" Property="Margin" Value="10,10,0,0"/>
                    </DataTrigger>

                    <DataTrigger Binding="{Binding PrsID}" Value="-1">
                        <Setter TargetName="schemaID" Property="Visibility" Value="Collapsed"/>
                        <Setter TargetName="prsId" Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                    
                </DataTemplate.Triggers>
                
            </DataTemplate>
            
        </Grid.Resources>
        
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="240"/>
            <ColumnDefinition Width="400"/>
            <!--<ColumnDefinition Width="Auto"/>-->
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Border BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Margin="5,5,5,0" Padding="5" >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>

                <Grid Visibility="{Binding IsSingleItem, Converter={StaticResource boolInverVis}}" Height="30">
                    <CheckBox IsChecked="{Binding ShowInactive}" VerticalAlignment="Center">
                        <TextBlock Text="Inaktive anzeigen"/>
                    </CheckBox>
                    <Button VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding ChangeStatusCommand}" Visibility="{Binding IsAktivieren, Converter={StaticResource boolToVis}}">
                        <TextBlock Text="Aktivieren" />
                    </Button>
                    <Button VerticalAlignment="Center" HorizontalAlignment="Right" Command="{Binding ChangeStatusCommand}" Visibility="{Binding IsAktivieren, Converter={StaticResource boolInverVis}}">
                        <TextBlock Text="Deaktivieren" />
                    </Button>
                </Grid>

                <ListBox ItemsSource="{Binding PlanLayouts}" SelectedItem="{Binding ActiveListItem}" Grid.Row="1"/>
                
                <!--<DataGrid Grid.Row="1" ItemsSource="{Binding PlanLayouts}"
                      SelectedItem="{Binding ActiveGridItem}"
                      CanUserAddRows="False"
                      AutoGenerateColumns="False"
                      CanUserSortColumns="False"
                      VerticalScrollBarVisibility="Auto"
                  Background="White"
                  BorderBrush="Black"
                      >
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding AbteilungID}" MinWidth="40"/>
                        <DataGridTextColumn Header="Name" IsReadOnly="True" Binding="{Binding Name}" MinWidth="100"/>
                    </DataGrid.Columns>
                </DataGrid>-->
            </Grid>
        </Border>

        <GridSplitter Width="4" Background="Transparent"/>

        <!--<Border BorderBrush="Black" BorderThickness="1" Background="White" Margin="5,5,5,0" Padding="5" Grid.Column="1">-->
        <GroupBox Margin="5,5,5,0" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                
                <Grid Margin="0,5,5,20">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Name" Margin="0,0,20,0"/>
                    <TextBox DataContext="{Binding ActiveListItem}" Text="{FocusBinding Path=Name}" IsEnabled="{Binding IsNew}" Grid.Column="1" VerticalAlignment="Center"/>
                </Grid>

                <ListBox Grid.Row="1" ItemsSource="{Binding SelectedPlanLayout}" SelectedItem="{Binding SelectedPlanlayoutItem}" Background="Transparent" BorderBrush="Black" x:Name="LayoutList"
                         PreviewMouseLeftButtonDown="LayoutList_PreviewMouseLeftButtonDown"
                         Drop="LayoutList_Drop" AllowDrop="True">
                    <!--SelectedItem="{Binding SelectedPlanLayoutItem}"-->
                    <!--<ListBox.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="PrsID" Value="0"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="ItemTemplate" Value="{StaticResource abteilungSchemaItem}"/>
                        </MultiDataTrigger>
                    </ListBox.Triggers>-->
                </ListBox>
                
                <!--<DataGrid Grid.Row="1" ItemsSource="{Binding SelectedPlanLayout}"
                      SelectedItem="{Binding SelectedLayoutItem}"
                      CanUserAddRows="False"
                      AutoGenerateColumns="False"
                      CanUserSortColumns="False"
                      VerticalScrollBarVisibility="Auto"
                  Background="Transparent"
                  BorderBrush="Black"
                      >
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Position" IsReadOnly="True" Binding="{Binding PersonSchemaID}" MinWidth="40"/>
                        <DataGridTextColumn Header="ID" IsReadOnly="True" Binding="{Binding PrsID}" MinWidth="40"/>
                        <DataGridTextColumn Header="Vorname" IsReadOnly="True" Binding="{Binding Vorname}" MinWidth="100"/>
                        <DataGridTextColumn Header="Nachname" IsReadOnly="True" Binding="{Binding Nachname}" MinWidth="100"/>
                        <DataGridTextColumn Header="Abteilung" IsReadOnly="True" Binding="{Binding AbteilungName}" MinWidth="100"/>
                    </DataGrid.Columns>
                </DataGrid>-->
            </Grid>
        </GroupBox>

        <Grid Grid.Column="2" Margin="40,20,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="8*"/>
                <ColumnDefinition Width="2*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="19"/>
                <RowDefinition Height="10" />
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="50"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Button Margin="5" Command="{Binding AddAbteilungCommand}" Grid.RowSpan="2">
                <TextBlock Text="Teams bearbeiten"/>
            </Button>
            <Button Grid.Row="2" Margin="5" Command="{Binding AddPersonCommand}">
                <TextBlock Text="Einzelne Zeile einfügen"/>
            </Button>
            <Button Grid.Row="3" Margin="6,5,4,5" Command="{Binding DeleteRowCommand}" CommandParameter="{Binding SelectedItem, ElementName=LayoutList}">
                <TextBlock Text="Zeile entfernen"/>
            </Button>
            <Button Grid.Row="5" Margin="5" Command="{Binding AddServicesCommand}" Visibility="{Binding IsSingleItem, Converter={StaticResource boolInverVis}}">
                <TextBlock Text="Dienste zuweisen"/>
            </Button>

            <TextBlock Grid.Row="6" Text="Farbe" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="7,7,0,0" FontWeight="Heavy"/>
            
            <c:ColorPicker Grid.Row="7" Margin="5" SelectedColor="{Binding SelectedPlanlayoutItem.Color}" />

            <TextBlock Grid.Row="8" Margin="5" Text="{x:Static p:Resources.PlanLayoutDescription}" TextWrapping="Wrap" Grid.ColumnSpan="2"/>
        </Grid>

        <StackPanel Grid.Row="1" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" Command="{Binding DeleteCommand}">
                <TextBlock Text="{x:Static p:Resources.Delete}"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding NewCommand}" Visibility="{Binding IsSingleItem, Converter={StaticResource boolInverVis}}">
                <TextBlock Text="{x:Static p:Resources.New}"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding CopyCommand}" Visibility="{Binding IsSingleItem, Converter={StaticResource boolInverVis}}">
                <TextBlock Text="{x:Static p:Resources.Copy}"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding SaveCommand}">
                <TextBlock Text="{x:Static p:Resources.Save}"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsDefault="True" Command="{Binding OkCommand}">
                <TextBlock Text="{x:Static p:Resources.Ok}"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" Command="{Binding CancelCommand}">
                <TextBlock Text="{x:Static p:Resources.Cancel}"/>
            </Button>
        </StackPanel>
    </Grid>
    
</c:BaseControl>
